package com.fau.wm.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * 库存调拨详细
 * @author liy
 * @since 2014年7月24日,下午5:23:25
 */
@Entity
@Table(name = "medical_allocation_detail")
public class MedicalAllocationDetail implements Serializable, JSONAware {

	private static final long serialVersionUID = 7462413854691482812L;
	
	private String id;
	private String allocationId;	// 调拨表id
	private String medicineId;		// 药品id
	private Integer quantity;		// 数量
	private Date createTime = new Date();		// 创建时间
	private Date updateTime = new Date();		// 更新时间
	
	private String recallWhId;					// 调出仓库id
	private MedicalMedicine medicine;			// 药品实体类
	private String warehouseId;
	private MedicalAllocation allocation;		// 调拨表实体类
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	@Transient
	public String getAllocationId() {
		return allocationId;
	}
	
	public void setAllocationId(String allocationId) {
		this.allocationId = allocationId;
	}
	
	@Transient
	public String getMedicineId() {
		return medicineId;
	}
	
	public void setMedicineId(String medicineId) {
		this.medicineId = medicineId;
	}
	
	@Column(name = "quantity", length = 10)
	public Integer getQuantity() {
		return quantity;
	}
	
	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}
	
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	@Transient
	public String getRecallWhId() {
		return recallWhId;
	}

	public void setRecallWhId(String recallWhId) {
		this.recallWhId = recallWhId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "medicine_id")
	public MedicalMedicine getMedicine() {
		return medicine;
	}

	public void setMedicine(MedicalMedicine medicine) {
		this.medicine = medicine;
	}

	@Transient
	public String getWarehouseId() {
		return warehouseId;
	}

	public void setWarehouseId(String warehouseId) {
		this.warehouseId = warehouseId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "allocation_id")
	public MedicalAllocation getAllocation() {
		return allocation;
	}

	public void setAllocation(MedicalAllocation allocation) {
		this.allocation = allocation;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("medicineSerialNum", medicine.getSerialNum());
		obj.put("medicineName", medicine.getName());
		obj.put("medicineId", medicine.getId());
		obj.put("medicineUnit", medicine.getUnitValue());
		obj.put("quantity", quantity);
		obj.put("allocationId", allocation.getId());
		obj.put("createTime", DateFormatUtils.format(createTime, "yyyy-MM-dd HH:mm:ss"));
		return obj.toString();
	}
	
	
}
